﻿using System.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Home_School
{
    public partial class frmStudent : Form
    {
        public frmStudent()
        {
            InitializeComponent();
        }
        public SqlConnection cn;
        public SqlCommand cmd;
           

        void con()
        {
            cn = new SqlConnection("server=.; uid=sa; pwd=123; database=student_info_db;");
            cn.Open();
        }
        void reload()
        {
            con();
            cmd = new SqlCommand("select * from tblstudent where upper(stu_code+stu_name_kh+stu_name_eng) like upper(N'%" + txtSearch.Text  + "%');", cn);
            try
            {
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                BindingSource bs = new BindingSource();
                bs.DataSource = dt;
                dataGridView1.DataSource = bs;
                da.Update(dt);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void frmStudent_Load(object sender, EventArgs e)
        {
            this.reload(); 
        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            this.reload();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            frmstudentEditer showformstu_ed = new frmstudentEditer();
            showformstu_ed.ShowDialog();
        }
         

        //private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        //{
           

        //    try
        //    {
        //        if (dataGridView1.RowCount > 0)
        //        {
        //            int i = dataGridView1.CurrentCell.RowIndex;
                 
        //        }
        //}
        //    }
    }
}
